import QtQuick 2.12
import QtQuick.Controls 2.12

// IMX6ULL优化版启动画面 - 无OpenGL依赖
Item {
    id: splashScreen
    anchors.fill: parent
    
    signal finished()
    
    // 深色科技背景
    Rectangle {
        anchors.fill: parent
        gradient: Gradient {
            GradientStop { position: 0.0; color: "#0a0e27" }
            GradientStop { position: 0.5; color: "#1a1e3f" }
            GradientStop { position: 1.0; color: "#0a0e27" }
        }
    }
    
    // 静态网格线背景 
    Repeater {
        model: 20
        Rectangle {
            x: index * 50
            y: 0
            width: 1
            height: parent.height
            color: "#00d4ff"
            opacity: 0.15
        }
    }
    
    Repeater {
        model: 12
        Rectangle {
            x: 0
            y: index * 50
            width: parent.width
            height: 1
            color: "#00d4ff"
            opacity: 0.15
        }
    }
    
    // 中央主容器
    Item {
        anchors.centerIn: parent
        width: parent.width
        height: parent.height
        
        // 简化版旋转光环 (3个)
        Repeater {
            model: 3
            
            Rectangle {
                width: 250 + index * 70
                height: width
                radius: width / 2
                anchors.centerIn: parent
                color: "transparent"
                border.color: Qt.rgba(0, 0.83, 1, 0.3 - index * 0.08)
                border.width: 2
                
                RotationAnimation on rotation {
                    from: 0
                    to: 360
                    duration: 6000 + index * 2000
                    loops: Animation.Infinite
                    direction: index % 2 === 0 ? RotationAnimation.Clockwise : RotationAnimation.Counterclockwise
                }
                
                opacity: fadeInAnim.opacity
            }
        }
        
        // 中心脉冲圆 - 无发光特效
        Rectangle {
            id: centerCircle
            width: 180
            height: 180
            radius: 90
            anchors.centerIn: parent
            color: Qt.rgba(0, 0.83, 1, 0.15)
            border.color: "#00d4ff"
            border.width: 3
            
            // 简化的脉冲效果
            SequentialAnimation on scale {
                running: true
                loops: Animation.Infinite
                NumberAnimation { from: 1.0; to: 1.12; duration: 1200; easing.type: Easing.InOutQuad }
                NumberAnimation { from: 1.12; to: 1.0; duration: 1200; easing.type: Easing.InOutQuad }
            }
            
            // 外围圆环
            Rectangle {
                anchors.centerIn: parent
                width: parent.width * 1.4
                height: parent.height * 1.4
                radius: width / 2
                color: "transparent"
                border.color: Qt.rgba(0, 0.83, 1, 0.25)
                border.width: 2
                
                SequentialAnimation on opacity {
                    running: true
                    loops: Animation.Infinite
                    NumberAnimation { from: 0.3; to: 0.7; duration: 1500; easing.type: Easing.InOutQuad }
                    NumberAnimation { from: 0.7; to: 0.3; duration: 1500; easing.type: Easing.InOutQuad }
                }
            }
        }
        
        // Logo和文字区域
        Column {
            anchors.centerIn: parent
            spacing: 15
            
            // 简化的图标 - 使用Rectangle代替Canvas
            Item {
                width: 70
                height: 70
                anchors.horizontalCenter: parent.horizontalCenter
                
                // 六边形简化版 - 使用矩形组合
                Rectangle {
                    width: 50
                    height: 50
                    anchors.centerIn: parent
                    color: Qt.rgba(0, 0.83, 1, 0.25)
                    border.color: "#00d4ff"
                    border.width: 3
                    rotation: 45
                    
                    RotationAnimation on rotation {
                        from: 45
                        to: 405
                        duration: 4000
                        loops: Animation.Infinite
                    }
                }
                
                Rectangle {
                    width: 35
                    height: 35
                    anchors.centerIn: parent
                    color: "transparent"
                    border.color: "#00d4ff"
                    border.width: 2
                }
            }
            
            // 应用名称 - 简化版无发光效果
            Text {
                text: "IMX6ULL"
                font.pixelSize: 38
                font.bold: true
                font.family: "Arial"
                color: "#00d4ff"
                anchors.horizontalCenter: parent.horizontalCenter
                
                SequentialAnimation on opacity {
                    running: true
                    loops: Animation.Infinite
                    NumberAnimation { from: 0.7; to: 1.0; duration: 1500 }
                    NumberAnimation { from: 1.0; to: 0.7; duration: 1500 }
                }
            }
            
            Text {
                text: "车载智能系统"
                font.pixelSize: 16
                color: "#88ccff"
                anchors.horizontalCenter: parent.horizontalCenter
                opacity: 0.85
            }
        }
        
        // 简化的扫描线效果
        Rectangle {
            id: scanLine
            width: parent.width * 0.8
            height: 2
            anchors.horizontalCenter: parent.horizontalCenter
            color: Qt.rgba(0, 0.83, 1, 0.6)
            y: -height
            
            property var parentContainer: parent
            
            SequentialAnimation on y {
                running: true
                loops: Animation.Infinite
                NumberAnimation { 
                    from: -scanLine.height
                    to: scanLine.parentContainer ? scanLine.parentContainer.height : 600
                    duration: 3000
                    easing.type: Easing.Linear
                }
                PauseAnimation { duration: 500 }
            }
        }
        
        // 底部加载进度
        Column {
            anchors.bottom: parent.bottom
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.bottomMargin: 60
            spacing: 12
            
            // 加载文字
            Text {
                id: loadingText
                text: "系统初始化中"
                font.pixelSize: 15
                color: "#00d4ff"
                anchors.horizontalCenter: parent.horizontalCenter
                
                property int dotCount: 0
                
                Timer {
                    interval: 500
                    running: true
                    repeat: true
                    onTriggered: {
                        loadingText.dotCount = (loadingText.dotCount + 1) % 4
                        var dots = ""
                        for (var i = 0; i < loadingText.dotCount; i++) {
                            dots += "."
                        }
                        loadingText.text = "系统初始化中" + dots
                    }
                }
            }
            
            // 进度条容器
            Rectangle {
                width: 280
                height: 4
                color: Qt.rgba(0, 0.83, 1, 0.25)
                radius: 2
                anchors.horizontalCenter: parent.horizontalCenter
                
                Rectangle {
                    id: progressBar
                    width: 0
                    height: parent.height
                    color: "#00d4ff"
                    radius: parent.radius
                }
            }
            
            // 进度百分比
            Text {
                id: progressText
                text: "0%"
                font.pixelSize: 13
                color: "#88ccff"
                anchors.horizontalCenter: parent.horizontalCenter
            }
        }
        
        // 简化的粒子效果 - 减少数量
        Repeater {
            model: 15
            
            Rectangle {
                id: particle
                width: 2
                height: 2
                radius: 1
                color: "#00d4ff"
                opacity: 0.4
                x: Math.random() * splashScreen.width
                
                property real initialY: Math.random() * splashScreen.height
                y: initialY
                
                SequentialAnimation on y {
                    running: true
                    loops: Animation.Infinite
                    NumberAnimation { 
                        from: particle.initialY
                        to: particle.initialY - 150
                        duration: 3000
                        easing.type: Easing.InOutQuad
                    }
                    ScriptAction {
                        script: {
                            particle.y = splashScreen.height
                            particle.initialY = splashScreen.height
                        }
                    }
                }
            }
        }
    }
    
    // 整体淡入动画
    PropertyAnimation {
        id: fadeInAnim
        target: fadeInAnim
        property: "opacity"
        from: 0
        to: 1
        duration: 1000
        running: true
        
        property real opacity: 0
    }
    
    // 进度条动画
    NumberAnimation {
        id: progressAnim
        target: progressBar
        property: "width"
        from: 0
        to: 280
        duration: 3000
        running: true
        easing.type: Easing.InOutQuad
        
        onRunningChanged: {
            if (!running) {
                fadeOutAnim.start()
            }
        }
    }
    
    // 同步更新百分比文本
    Timer {
        interval: 50
        running: progressAnim.running
        repeat: true
        onTriggered: {
            var progress = Math.round((progressBar.width / 280) * 100)
            progressText.text = progress + "%"
        }
    }
    
    // 淡出动画
    NumberAnimation {
        id: fadeOutAnim
        target: splashScreen
        property: "opacity"
        from: 1
        to: 0
        duration: 600
        easing.type: Easing.InOutQuad
        
        onStopped: {
            splashScreen.finished()
        }
    }
}

